#include "ipclogicmanager.h"

int IPCLogicManager::do_request(QString &cmd, QByteArray &args)
{
    AsyCop::do_request(cmd,args);
    if( cmd == SLOT(onRecieveServerData(const QByteArray &)))
    {
        QByteArray data;
        AsyCop::mXml->parseArgs2(args,data);
        printf("do_request,onRecieveServerData arg:%s\n",data.data());
        mLogic->onReceivedServerData(data);
    }
    else if( cmd == SLOT(onServerNotify(int)))
    {
        int code;
        AsyCop::mXml->parseArgs1(args,code);
        printf("do_request,onServerNotify arg:%d\n",code);
        mLogic->onServerNotify(code);
    }
    else if( cmd == SLOT(onReceivedData(const QString &, const QByteArray &)))
    {
        QString ip;
        QByteArray data;
        AsyCop::mXml->parseArgs3(args,ip,data);
        printf("do_request,onReceivedData arg:%s:%s\n",ip.toAscii().data(),data.data());
        mLogic->onReceivedData(ip,data);
    }
    else if( cmd == SLOT(onNotify(const QString &, int)))
    {
        QString ip;
        int code;
        AsyCop::mXml->parseArgs4(args,ip,code);
        printf("do_request,onNotify arg:%s:%d\n",ip.toAscii().data(),code);
        mLogic->onNotify(ip,code);
    }

}

int IPCLogicManager::init()
{
    AsyCop::init();
    connect( mLogic,SIGNAL(sendServerData(const QByteArray &)),this,SLOT(onSendServerData(const QByteArray)));
    connect(mLogic, SIGNAL(sendData(const QString &, const QByteArray &)), this,SLOT(onSendData(const QString, const QByteArray)));     
}

void IPCLogicManager::onSendData(const QString &ip,const QByteArray &data)
{
    QByteArray args;
    AsyCop::mXml->packetArgs3(args,ip,data);
    QString cmd(SLOT(onSendData(QString, QByteArray)));
    send_request(cmd,args,L2N);
}

void IPCLogicManager::onSendServerData(const QByteArray &data)
{
    QByteArray args;
    AsyCop::mXml->packetArgs2(args,(QByteArray &)data);
    QString cmd(SLOT(onSendServerData(QByteArray)));
    send_request(cmd,args,L2N);
}

